package com.hanxry.concurrent;

import java.io.Serializable;

/**
 * 用于数据切割
 */
public class IntervalData<T> implements Serializable {
    private static final long serialVersionUID = -6941092506360743978L;
    private T begin;
    private T end;
    private int step;

    public IntervalData(T begin, T end, int step) {
        this.begin = begin;
        this.end = end;
        this.step = step;
    }

    /**
     * 获取 length
     *
     * @return length
     */
    public int getStep() {
        return step;
    }

    /**
     * 设置 length
     *
     * @param length
     */
    public void setStep(int step) {
        this.step = step;
    }

    /**
     * 获取 begin
     *
     * @return begin
     */
    public T getBegin() {
        return begin;
    }

    /**
     * 设置 begin
     *
     * @param begin
     */
    public void setBegin(T begin) {
        if (begin == null)
            throw new RuntimeException("It may cause an infinite loop...");
        this.begin = begin;
    }

    /**
     * 获取 end
     *
     * @return end
     */
    public T getEnd() {
        return end;
    }

    /**
     * 设置 end
     *
     * @param end
     */
    public void setEnd(T end) {
        if (end == null)
            throw new RuntimeException("It may cause an infinite loop...");
        this.end = end;
    }

    /*
     * (non-Javadoc)
     *
     * @see java.lang.Object#toString()
     */
    @Override
    public String toString() {
        return "IntervalData [begin=" + begin + ", end=" + end + ", length=" + step + "]";
    }

}
